<?php
include_once("../includes/common.php");
include_once("../class/User.class.php");
include_once("../class/Explore.class.php");
require_once("../islogin.php");

if ($isadmin!=1){
    header('Location: /');
    exit;
}

$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];


//页面配置
$nowPage = $_GET['page'] ?? 1;
if($nowPage<0){
    exit('page error');
}
$pageName = "视频封面状态";

//页面数据
$explore = new Explore();
$res = json_decode($explore->getVideoSrc(),true);
if(!$res){
    $res = [];
}
if (isset($_GET['clear'])) {
    $explore->clearVideoSrc();

    header("Location: video_src.php");
    exit();
}

?>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <?php require_once('head.php'); ?>
    <style>
        .text-del-line{
            text-decoration: line-through;
        }
    </style>
</head>
<body>

<!--==================== Preloader Start ====================-->
<div class="preloader">
    <div class="loader"></div>
</div>
<!--==================== Preloader End ====================-->

<!--==================== Sidebar Overlay End ====================-->
<div class="side-overlay"></div>
<!--==================== Sidebar Overlay End ====================-->

<?php require_once('menu.php'); ?>

<div class="dashboard-main-wrapper">
    <?php require_once('top_navbar.php'); ?>

    <div class="dashboard-body">

        <div class="row gy-4">
            <div class="card">
                <div class="card-body">
                    <h4 class="mb-12"><?php echo $pageName;?> <a href="?clear" class="btn btn-main rounded-pill py-9">清理已完成提取任务</a></h4>
                    <?php if (!$res){echo '没有任何任务 ~';}?>
                    <?php for ($i = 0; $i < count($res); $i++) { ?>
                        <div onclick="window.location.href='/explore.php?id=<?php echo $res[$i]["note_id"];?>'" class="recent-post rounded-8 border border-gray-100 p-16 d-flex gap-12 mb-16">
                            <div class="d-inline-flex w-100 max-w-130 flex-shrink-0">
                                <img src="<?php echo getFirstValidImage($res[$i]["image"]);?>" alt="" class="rounded-6 cover-img max-w-130 max-h-200">
                            </div>
                            <div>
                                <h4><?php echo $res[$i]["title"];?></h4>
                                <p class="text-gray-600 text-line-3"><?php echo mb_substr($res[$i]["content"], 0, 46, 'UTF-8');?>...</p>
                                <div class="flex-align gap-8 mt-24">
                                    <span class="text-gray-600 text-13">
                                        <?php
                                        $check_result = $res[$i]['is_ok'];

                                        switch ($check_result) {
                                            case 0:
                                                echo '<span class="text-13 py-2 px-10 rounded-pill bg-warning-50 text-warning-600 mb-16">提取中</span>';
                                                break;
                                            case 1:
                                                echo '<span class="text-13 py-2 px-10 rounded-pill bg-success-50 text-success-600 mb-16">提取成功</span>';
                                                break;
                                            case 2:
                                                echo '<span class="text-13 py-2 px-10 rounded-pill bg-danger-50 text-danger-600 mb-16">提取失败</span>';
                                                break;
                                        }
                                        ?>
                                    </span>
                                </div>
                            </div>
                        </div>
                    <?php } ?>


                </div>
            </div>

        </div>

    </div>

    <?php require_once('footer.php'); ?>
</div>


<?php require_once('foot.php'); ?>

</body>
</html>